//商家详情 0
//商家修改  1

define(function(require, exports, module){
	"require:nomunge,exports:nomunge,module:nomunge";
	//异步请求
var wind_async=require('ddf_wind_async');
require('constants_shop');
var base=require('component-base');
var history=require('component-history');
var dialog=require('component-dialog');
var upload=require('component-upload');
var map = require('map');
require('component-location');
require('component-page');
var addTime =0;

var provinceId,cityId,regionId;


/**
 * 查询商家详情
 */

exports.init=function(m){
    history.addHis(this,arguments);//增加历史	
    window.$ddf_shop = m;
	var htmlStr="";
	htmlStr += '<div id="content-header"><div id="breadcrumb"> <a href=javascript:load("'+ddf.index.index_js+'") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href="javascript:void(0)" class="current">商家详情</a></div></div>';
	htmlStr += '<div class="container-fluid">';
	htmlStr += '<div class="row-fluid">';
	htmlStr += '<div class="span12">';
	htmlStr += '<div id="alert-tips0" ></div>';
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title"><span class="icon"><i class="icon-pencil"></i></span><h5>操作</h5></div>    ';
	htmlStr += '<div class="widget-content"><div class="div-btn">';
	htmlStr += '<button class="btn btn-success" id="updateShopMessage" type="button" onClick="$ddf_shop.editShop()">修改</button>&nbsp;&nbsp;';
	htmlStr += '<button class="btn btn-primary" type="button" onClick="$ddf_shop.openShopPhotos()">商家相册管理</button>';
	htmlStr += '&nbsp;&nbsp;<button class="btn btn-success" type="button" onClick="$ddf_shop.setDomain()">个性域名设置</button>';
//	htmlStr += '<div class="btn-group pull-right">';
//	htmlStr += '<button data-toggle="dropdown" class="btn btn-success"><span id="businessStatusName"></span><span class="caret"></span></button>';
//	htmlStr += '<ul class="dropdown-menu">';
//	htmlStr += '<li><a href=javascript:$ddf_shop.setBusinessStatus("1")>营业中</a></li>';
//	htmlStr += '<li><a href=javascript:$ddf_shop.setBusinessStatus("2")>休息中</a></li>';
//	htmlStr += '</ul>';
//	htmlStr += '</div> ';

	htmlStr += ' <div class="btn-group" id="changeStatusBar" style="display:none;"><button data-toggle="dropdown" class="btn dropdown-toggle">';
	htmlStr += '<span id="show_shopStatusName"></span>&nbsp;&nbsp;<span class="caret"></span></button>';
	htmlStr += '<ul class="dropdown-menu">';
	htmlStr += '<li><a href=javascript:$ddf_shop.setBusinessStatus("1","营业中")>设为营业中</a></li>';
	htmlStr += '<li><a href=javascript:$ddf_shop.setBusinessStatus("2","休息中")>设为休息中</a></li>';
	htmlStr += '</ul></div>';
	
		
	htmlStr += '</div></div>';
	
	
	
	htmlStr += '</div>  ';
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span><h5>商家详情</h5></div>';
	htmlStr += '<div class="widget-content nopadding">';
	htmlStr += '<div class="form-horizontal">';
	
	htmlStr += '<div class="control-group"><label class="control-label">商家LOGO：</label><div class="controls"><div class="logoSize"><img id="show_logoUrl" src="" /></div></div></div>       ';
	htmlStr += '<div class="control-group"><label class="control-label">商家二维码：</label><div class="controls"><div class="logoSize"><img id="shopCode" /><iframe   width=0   height=0   frameborder=0   name=hrong   style="display:   none"></iframe> <div style="padding-top:10px;"><button class="btn btn-primary" type="button" onclick=javascript:$ddf_shop.showDownMerCode()>下载二维码</button></div></div></div>       ';
	htmlStr += '<div class="control-group"><label class="control-label">商家类型：</label><div class="controls"><span class="inp_span" id="show_shopTypeName"></span></div></div>';
	
	htmlStr += '<div class="control-group"><label class="control-label">商家名称：</label><div class="controls"><span class="inp_span" id="show_shopName"></span></div></div>';
	htmlStr += '<div class="control-group"><label class="control-label">商家简介：</label><div class="controls"><pre class="inp_span" id="show_introduce"></pre></div></div>';
	htmlStr += '<div class="control-group"><label class="control-label">公司名称：</label><div class="controls"><span class="inp_span" id="show_comName"></span></div></div>';

	htmlStr += '<div class="control-group"><label class="control-label">代理商名称：</label><div class="controls"><span class="inp_span" id="show_agentName"></span></div></div>';

	//htmlStr += '<div class="control-group"><label class="control-label">POS商户号：</label><div class="controls"><span class="inp_span" id="show_merchantNo"></span></div></div>';
	//htmlStr += '<div class="control-group"><label class="control-label">POS商户名称：</label><div class="controls"><span class="inp_span" id="show_merchantName"></span></div></div>';
	
	htmlStr += '<div class="control-group"><label class="control-label">所在省份：</label><div class="controls"><span class="inp_span" id="show_provinceName"></span></div></div>';
	htmlStr += '<div class="control-group"><label class="control-label">所在城市：</label><div class="controls"><span class="inp_span" id="show_cityName"></span></div></div>';
	htmlStr += '<div class="control-group"><label class="control-label">所在区域：</label><div class="controls"><span class="inp_span" id="show_regionName"></span></div></div>';
	htmlStr += '<div class="control-group"><label class="control-label">街道：</label><div class="controls"><span class="inp_span" id="show_street"></span></div></div>';
	htmlStr += '<div class="control-group"><label class="control-label">地址：</label><div class="controls"><span class="inp_span" id="show_address"></span></div></div>';
	
	htmlStr += '<div class="control-group"><label class="control-label">联系人：</label><div class="controls"><span class="inp_span" id="show_contact"></span></div></div>';

	htmlStr += '<div class="control-group"><label class="control-label">联系电话：</label><div class="controls"><span class="inp_span" id="show_phone"></span></div></div>';
	htmlStr += '<div class="control-group"><label class="control-label">手机号码：</label><div class="controls"><span class="inp_span" id="show_mobile"></span></div></div>';
	htmlStr += '<div class="control-group"><label class="control-label">接收消息手机号：</label><div class="controls"><span class="inp_span" id="show_msg_mobile"></span></div></div>';
	

	htmlStr += '<div class="control-group"><label class="control-label">营业时间：</label><div class="controls"><span class="inp_span" id="show_businessHours"></span></div></div>';
	htmlStr += '<div class="control-group"><label class="control-label">营业状态模式：</label><div class="controls"><span class="inp_span" id="show_businessStatus_type"></span></div></div>';
	htmlStr += '<div class="control-group"><label class="control-label">营业状态：</label><div class="controls"><span class="inp_span" id="show_businessStatus"></span></div></div>';
	htmlStr += '<div class="control-group"><label class="control-label">起送金额：</label><div class="controls"><span class="inp_span" id="show_minAmount"></span></div></div>';
	htmlStr += '<div class="control-group"><label class="control-label">配送方式：</label><div class="controls"><span class="inp_span" id="show_shopDelivery"></span></div></div>';
	htmlStr += '<div class="control-group"><label class="control-label">配送范围：</label><div class="controls"><span class="inp_span" id="show_range"></span></div></div>';
	htmlStr += '<div class="control-group"><label class="control-label">配送费：</label><div class="controls"><span class="inp_span" id="show_deliveryAmount"></span></div></div>';
	htmlStr += '<div class="control-group"><label class="control-label">送达时间：</label><div class="controls"><span class="inp_span" id="show_shipTime"></span></div></div>';
	
	htmlStr += '<div class="control-group"><label class="control-label">地图：</label><div class="controls"><div><div style="width: 520px; height: 340px; border: 1px solid gray" id="allmap-select"></div></div></div></div>';
	htmlStr += '<div class="control-group"><label class="control-label">经度：</label><div class="controls"><span class="inp_span" id="show_longitude"></span></div></div>';
	htmlStr += '<div class="control-group"><label class="control-label">纬度：</label><div class="controls"><span class="inp_span" id="show_latitude"></span></div></div>';
	
	//htmlStr += '<div class="control-group"><label class="control-label">刷卡费率：</label><div class="controls"><span class="inp_span" id="show_mcc"></span></div></div>';
	htmlStr += '<div class="control-group"><label class="control-label">备注：</label><div class="controls"><span class="inp_span" id="show_memo"></span></div></div>';
	
	

	htmlStr += '</div>  ';
	htmlStr += '</div>          ';
	htmlStr += '</div>  ';
	htmlStr += '</div>';
	htmlStr += '</div> ';
	htmlStr += '</div> ';

	showDiv("content0");
	$("#content0").html(htmlStr);
    base.showLoading();
    
    
//	DDF_AsyncRequest("POST",ddf.shop.getShopsById,"",'$ddf_shop.loadShopDetailCallBack(data)');
//    eval(Wind.compile("async",function(){
//		
//		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.shop.getShopsById,""));
//		
//		loadShopDetailCallBack(data);
//		
//	}))().start();
	
	loadShopMessage();
}
    
   function loadShopMessage(){
    	
    	eval(Wind.compile("async",function(){
    		
    		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.shop.getShopsById,""));
    		
    		loadShopDetailCallBack(data);
    		
    	}))().start();
    	
    }

/**
 * 商家详情回调函数
 */
var shopDataArray={};
var deliveryIdHtml="",deliveryHtml="";
function loadShopDetailCallBack(data){
	deliveryIdHtml="";
	deliveryHtml="商家配送 ,";
	if(data["code"] == 1){
    
	//保存到数组中
	shopDataArray["LOGO_URL"]=data["LOGO_URL"];
	shopDataArray["SHOP_ID"]=data["SHOP_ID"];
	shopDataArray["COM_NAME"]=data["COM_NAME"];
	shopDataArray["SHOP_TYPE_ID"]=data["SHOP_TYPE_ID"];
	shopDataArray["SHOP_TYPE_NAME"]=data["SHOP_TYPE_NAME"];
	shopDataArray["SHOP_NAME"]=data["SHOP_NAME"];
	shopDataArray["INTRODUCE"]=data["INTRODUCE"];
	shopDataArray["AGENT_ID"]=data["AGENT_ID"];
	shopDataArray["AGENT_NAME"]=data["AGENT_NAME"];
	shopDataArray["PROVINCE_ID"]=data["PROVINCE_ID"];
	shopDataArray["CITY_ID"]=data["CITY_ID"];
	shopDataArray["REGION_ID"]=data["REGION_ID"];
	shopDataArray["STREET"]=data["STREET"];
	shopDataArray["ADDRESS"]=data["ADDRESS"];
	shopDataArray["CONTACT"]=data["CONTACT"];
	shopDataArray["PHONE"]=data["PHONE"];
	shopDataArray["MOBILE"]=data["MOBILE"];
	shopDataArray["BUSINESS_HOURS"]=data["BUSINESS_HOURS"];
	shopDataArray["BUSINESS_STATUS"]=data["BUSINESS_STATUS"];
	shopDataArray["BUSINESS_STATUS_TYPE"]=data["BUSINESS_STATUS_TYPE"];
	shopDataArray["MIN_AMOUNT"]=data["MIN_AMOUNT"];
	shopDataArray["DELIVERY_AMOUNT"]=data["DELIVERY_AMOUNT"];
	shopDataArray["RANGE"]=data["RANGE"];
	shopDataArray["SHIP_TIME"]=data["SHIP_TIME"];
	shopDataArray["LONGITUDE"]=data["LONGITUDE"];
	shopDataArray["LATITUDE"]=data["LATITUDE"];
	shopDataArray["MCC"]=data["MCC"];
	shopDataArray["MEMO"]=data["MEMO"];
	shopDataArray["MERCHANT_NO"]=data["MERCHANT_NO"];
	shopDataArray["MERCHANT_NAME"]=data["MERCHANT_NAME"];
	shopDataArray["MSG_MOBILE"]=data["MSG_MOBILE"];
	shopDataArray["URL"]=data["URL"];
	shopDataArray["doneNum"]=data["doneNum"];
	shopDataArray["todoNum"]=data["todoNum"];

	for(var i=0;i<data["erpDeliverys"].length;i++){
		
		deliveryHtml+=data["erpDeliverys"][i]["DELIVERY_NAME"]+" ,";
		deliveryIdHtml+=data["erpDeliverys"][i]["DELIVERY_ID"]+",";
		
	}
	
	$("#show_logoUrl").attr("src",fileOpenUrl+shopDataArray["LOGO_URL"]);
	$("#show_shopTypeName").html(data["SHOP_TYPE_NAME"]);
	$("#show_shopName").html(data["SHOP_NAME"]);
	$("#show_introduce").html(data["INTRODUCE"]);
	$("#show_comName").html(data["COM_NAME"]);
	$("#show_agentName").html(data["AGENT_NAME"]);
	$("#show_provinceName").html(data["PROVINCE_NAME"]);
	$("#show_cityName").html(data["CITY_NAME"]);
	$("#show_regionName").html(data["REGION_NAME"]);
	$("#show_street").html(data["STREET"]);
	$("#show_address").html(data["ADDRESS"]);
	$("#show_contact").html(data["CONTACT"]);
	$("#show_phone").html(data["PHONE"]);
	$("#show_mobile").html(data["MOBILE"]);
	$("#show_businessHours").html(data["BUSINESS_HOURS"]);
	$("#show_msg_mobile").html(data["MSG_MOBILE"]);
	if(data["BUSINESS_STATUS"]=="1"){
		$("#show_businessStatus").html("营业中");
		$("#show_shopStatusName").html("营业中");
		
		$("#changeStatusBar").show();
	}else if(data["BUSINESS_STATUS"]=="2"){
		$("#show_businessStatus").html("休息中");
		$("#show_shopStatusName").html("休息中");
		$("#changeStatusBar").show();
	}else if(data["BUSINESS_STATUS"]=="3"){
		$("#show_businessStatus").html("审核中");
		$("#changeStatusBar").hide();
		$("#updateShopMessage").remove();
	}else if(data["BUSINESS_STATUS"]=="4"){
		$("#show_businessStatus").html("已结业");
		$("#changeStatusBar").hide();
		$("#updateShopMessage").remove();
	}
	if(data["BUSINESS_STATUS_TYPE"]=="1"){
		$("#show_businessStatus_type").html("手动");
	}else{
		$("#show_businessStatus_type").html("自动");
	}
	
	$("#show_minAmount").html(data["MIN_AMOUNT"]+" (元)");
	$("#show_shopDelivery").html(deliveryHtml);
	$("#show_range").html(data["RANGE"]+" (米)");
	$("#show_deliveryAmount").html(data["DELIVERY_AMOUNT"]+" (元)");
	$("#show_shipTime").html(data["SHIP_TIME"]+" (分)");
	$("#show_longitude").html(data["LONGITUDE"]);
	$("#show_latitude").html(data["LATITUDE"]);
	$("#show_mcc").html(data["MCC"]);
	$("#show_memo").html(data["MEMO"]);
	
	$("#show_merchantNo").html(data["MERCHANT_NO"]);
	$("#show_merchantName").html(data["MERCHANT_NAME"]);
	
	if(!isNull(data["SHOP_ID"])){
		if(window.location.port == "8082"){
			content = "http://120.27.46.32:8082/mall/reg?s="+data["SHOP_ID"];
		}else{
			content = "http://www.storeme.cn/mall/reg?m="+data["SHOP_ID"];
		}
		$("#shopCode").attr("src",CTX+"/QrCodeServlet?m=" + content+"&w=120&h=120")
	}
	
	
	map.allmap("allmap-select",data["LATITUDE"],data["LONGITUDE"],"");
	}else{
		base.tips_error(data["message"]);
	}
	base.cancelLoading();
}
/**
 * 设置个性域名
 */

exports.setDomain = function (){
	history.addHis(this,arguments);//增加历史
	base.showLoading();
	eval(Wind.compile("async",function(){
		
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.shop.getDomainByShopId,""));
		
		setDomainCallBack(data);
		
	}))().start();
};
/**
 * 设置个性域名回调函数
 */
function setDomainCallBack(data){
	if(data["code"] == 1){
		shopDataArray["URL"]=data["URL"];
		shopDataArray["doneNum"]=data["doneNum"];
		shopDataArray["todoNum"]=data["todoNum"];
		var htmlStr ="";
		htmlStr +='<div id="content-header"><div id="breadcrumb"> <a href=javascript:load("'+ddf.index.index_js+'") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href="#">商家管理</a><a href="javascript:void(0)" class="current">域名设置</a></div></div><div class="container-fluid"><div class="row-fluid"><div class="span12"><div class="widget-box"><div class="widget-title"><span class="icon"><i class="icon-reorder"></i></span><h5>操作</h5></div><div class="widget-content"><button type="button" class="btn btn-success" onClick="$ddf_shop.editDomain()">修改</button>&nbsp;&nbsp;<button type="button" class="btn btn-info" onclick=$ddf_shop.showDiv("content0")>返回</button></div></div><div class="widget-box"><div class="widget-title"><span class="icon"><i class="icon-th"></i></span><h5>设置域名</h5></div><div class="widget-content"><p>您店铺的初始域名：http://'+shopDataArray["SHOP_ID"]+'.storeme.cn</p><p>为您的店铺设置个性域名，方便用户直接打开</p><p>设置个性域名后，初始域名仍可使用</p><hr>'+
		'<p class="sitedomain"><span>您当前的个性访问域名为：'+'http://'+shopDataArray["URL"]+'.storeme.cn'+'</span><span class="sitedomain-settime"></span></p>'+
		'<p class="help-block">域名最多可以设置3次，您还可以设置'+shopDataArray["todoNum"]+'次</p> </div></div></div></div></div></div>';
		showDiv("content2");
		$("#content2").html(htmlStr);
		}else{
			base.tips_error(data["message"]);
		}
		base.cancelLoading();
}
/**
 * 修改域名
 */
exports.editDomain = function (){
	history.addHis(this,arguments);//增加历史
	var htmlStr ="";
	htmlStr +='<div id="content-header"><div id="breadcrumb"> <a href=javascript:load("'+ddf.index.index_js+'") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href="#">商家管理</a><a href="javascript:void(0)" class="current">域名设置</a></div></div><div class="container-fluid"><div class="row-fluid"><div class="span12"><div class="widget-box"><div class="widget-title"><span class="icon"><i class="icon-reorder"></i></span><h5>操作</h5></div><div class="widget-content"><button type="button" class="btn btn-primary" onClick="$ddf_shop.saveDomain()">保存</button>&nbsp;&nbsp;<button type="button" class="btn btn-info" onclick=$ddf_shop.setDomain()>返回</button></div></div><div class="widget-box"><div class="widget-title"><span class="icon"><i class="icon-th"></i></span><h5>设置域名</h5></div><div class="widget-content"><p>您店铺的初始域名：http://'+shopDataArray["SHOP_ID"]+'.storeme.cn</p><p>为您的店铺设置个性域名，方便用户直接打开</p><p>设置个性域名后，初始域名仍可使用</p><hr><div id="input_secondDomain" class="control-group"><div><p class="sitedomain"><span>http://<input type="text" class="span2" placeholder="2-8位字母、数字组合" id="secondDomain"/>.storeme.cn</span><button type="button" class="btn btn-warning" onClick="$ddf_shop.IsReg()">检测是否可用</button></p></div></div></div></div></div> </div></div></div>';
	$("#secondDomain").change(function() {
		var secondDomain=$("#secondDomain").val();
		if(!checkUsed(secondDomain)){
			addErrorMessage("input_secondDomain","secondDomain","个性域名非法");
		}else{
			clearErrorMessage("input_secondDomain");
		}
		
	});
	showDiv("content2");
	$("#content2").html(htmlStr);
};
/**
 * 保存域名
 */
exports.saveDomain =function  (){
	var secondDomain=$("#secondDomain").val();
	if(!checkUsed(secondDomain)){
		addErrorMessage("input_secondDomain","secondDomain","个性域名非法");
		return;
	}else{
		clearErrorMessage("input_secondDomain");
	}
	var params={"secondDomain":secondDomain};
	base.showLoading();
		eval(Wind.compile("async",function(){
			var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.shop.saveDomain,params));
			saveDomainCallBack(data);
		}))().start();
};
function saveDomainCallBack(data){
	if(data["code"]==1){
			base.tips(data["message"]);
			exports.setDomain();
		}else{
			base.tips_error(data["message"]);
	    }
		base.cancelLoading();
	}
function checkUsed(secondDomain){
	if("www"==secondDomain || "m"==secondDomain){
		return false;
	}else{
		///^[_A-Za-z0-9]+$/
		var reg = /^[a-zA-Z0-9$]{2,8}$/;
		return reg.test(secondDomain);
	}
};
/**
 * 检测个性域名是否注册使用过
 */
exports.IsReg = function (){
	if(checkUsed($("#secondDomain").val())){
		var secondDomain=$("#secondDomain").val();
		var params={"secondDomain":secondDomain};
		base.showLoading();
		eval(Wind.compile("async",function(){
			var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.shop.checkIsReg,params));
			IsRegCallBack(data);
		}))().start();
	}else{
		addErrorMessage("input_secondDomain","secondDomain","个性域名非法");
		return;
	}
}
function IsRegCallBack(data){
	if(data["code"]==1){
		clearErrorMessage("input_secondDomain");
		base.tips(data["message"]);
	}else{
		base.tips_error(data["message"]);
    }
	base.cancelLoading();
}
/**
 * 编辑商家资料
 */
function editShop(){
	history.addHis(this,arguments);//增加历史
	provinceId=shopDataArray["PROVINCE_ID"];
	
	cityId=shopDataArray["CITY_ID"];
	
	regionId=shopDataArray["REGION_ID"];
	
	agentId=shopDataArray["AGENT_ID"];
	
	shopTypeId=shopDataArray["SHOP_TYPE_ID"];
	
	var htmlStr="";
	

	htmlStr += '<div id="content-header">';
	htmlStr += '<div id="breadcrumb"> <a href=javascript:load("'+ddf.index.index_js+'") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href=javascript:$ddf_shop.showDiv("content0")>商家管理</a><a href="javascript:void(0)" class="current">编辑商家信息</a></div>';
	htmlStr += '</div>';

	htmlStr += '<div class="container-fluid">';
	htmlStr += '<div class="row-fluid">';
	htmlStr += '<div class="span12">';
	htmlStr += '<div id="alert-tips1" ></div>';
	htmlStr += '<div id="errorMessage-editShop" class="alert alert-error alert-block" style="display:none;">';
	htmlStr += '<a class="close" href="#" data-dismiss="alert">×</a>';
	htmlStr += '<h4 class="alert-heading">Error!</h4>';
	htmlStr += 'Youre not looking too good. Nulla vitae elit libero, a pharetra augue. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.';
	htmlStr += '</div>';

	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title"><span class="icon"><i class="icon-th"></i></span><h5>编辑商家信息</h5></div>';
	htmlStr += '<div class="widget-content nopadding">';
	htmlStr += '<div class="form-horizontal">	';
	
	
//	htmlStr += '<div class="control-group">';
//	htmlStr += '<label class="control-label">商家LOGO：</label>';
//	htmlStr += '<div class="controls">';
//	htmlStr += '<div class="upload_box">';
//	htmlStr += '<div class="picture">';
//	htmlStr += '<div class="default_pic"><p><img id="shopLogoUrl" src="'+fileOpenUrl+shopDataArray["LOGO_URL"]+'"><input type="hidden" id="shopLogoUrlInput" value="'+shopDataArray["LOGO_URL"]+'" /></p></div>';
//	htmlStr += '</div>';
//	htmlStr += '<input id="add_shop_logo_button" />';
//	htmlStr += '<div style="display:none;" class="progress progress-success progress-striped ">';
//	htmlStr += '<div class="bar" style="width: 0%;" id="prencentIcon"></div>  ';
//	htmlStr += '</div>';
//	htmlStr += '</div>';
//	
//	htmlStr += '</div>     ';
//	htmlStr += '</div>';
	
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label"><i class="required"></i>商家LOGO：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<div class="upload_box">';
	htmlStr += '<span id="add_shop_logo_button"></span>';
	htmlStr += '<div style="display:none;" class="progress progress-success progress-striped ">';
	htmlStr += '<div class="bar" style="width: 0%;" id="prencentIcon"></div>  ';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<div class="picture">';
	htmlStr += '<div class="default_pic"><p><img id="shopLogoUrl" src="'+fileOpenUrl+shopDataArray["LOGO_URL"]+'"><input type="hidden" id="shopLogoUrlInput" value="'+shopDataArray["LOGO_URL"]+'"  /></p></div>';
	htmlStr += '</div>';
	htmlStr += '</div>     ';
	htmlStr += '</div>';
	
	htmlStr += '<div class="control-group" id="control-group-shopID"><label class="control-label">商家代码：</label><div class="controls"><span class="inp_span" id="edit_shopId">'+shopDataArray["SHOP_ID"]+'</span></div></div>';
	htmlStr += '<div class="control-group" id="control-group-shopName"><label class="control-label">商家名称：</label><div class="controls"><input class="span9"  type="text" id="input-shopName" value="'+shopDataArray["SHOP_NAME"]+'"></div></div>';
	htmlStr += '<div class="control-group" id="control-group-introduce"><label class="control-label">商家简介：</label><div class="controls"><textarea class="span9" rows="5" type="text" id="input-introduce">'+shopDataArray["INTRODUCE"]+'</textarea></div></div>';
	htmlStr += '<div class="control-group" id="control-group-comName"><label class="control-label">公司名称：</label><div class="controls"><input class="span9"  type="text" id="input-comName" value="'+shopDataArray["COM_NAME"]+'"></div></div>';
	htmlStr += '<div class="control-group" ><label class="control-label">商家类型：</label><div class="controls"><input class="span9 alert_w"  id="input-shopType" type="text" value="'+shopDataArray["SHOP_TYPE_NAME"]+'" readonly onclick="$ddf_shop.openShopTypeDialog()" /></div></div>';
	htmlStr += '<div class="control-group"><label class="control-label">代理商名称：</label><div class="controls"><span class="inp_span">'+shopDataArray["AGENT_NAME"]+'</span<input type="hidden" id="input-agentId" value="'+shopDataArray["AGENT_ID"]+'" /></div></div>';
	
	//htmlStr += '<div class="control-group"><label class="control-label">POS商户号：</label><div class="controls"><span class="inp_span" id="input_merchantNo">'+shopDataArray["MERCHANT_NO"]+'</span></div></div>';
	//htmlStr += '<div class="control-group"><label class="control-label">POS商户名称：</label><div class="controls"><span class="inp_span" id="input_merchantName">'+shopDataArray["MERCHANT_NAME"]+'</span></div></div>';
	
	
	
	htmlStr += '<div class="control-group" id="control-group-area">';
	htmlStr += '<label class="control-label">省/市/区：</label>';
	htmlStr += '<div id="locationShowDiv"></div>';
//	htmlStr += '<div class="controls">';
//	htmlStr += '<div class="btn-group"><button data-toggle="dropdown" class="btn dropdown-toggle" ><span id="province-name">全国</span>&nbsp;&nbsp;<span class="caret"></span></button><ul class="dropdown-menu" id="select-province"></ul></div> ';
//	htmlStr += '<div class="btn-group"><button data-toggle="dropdown" class="btn dropdown-toggle" ><span id="city-name">全省</span>&nbsp;&nbsp;<span class="caret"></span></button><ul class="dropdown-menu" id="select-city"></ul></div>';
//	htmlStr += '<div class="btn-group"><button data-toggle="dropdown" class="btn dropdown-toggle" ><span id="region-name">全市</span>&nbsp;&nbsp;<span class="caret"></span></button><ul class="dropdown-menu" id="select-region"></ul></div>';
//	htmlStr += '</div>    ';
	htmlStr += '</div>';
	htmlStr += '<div class="control-group" id="control-group-street">';
	htmlStr += '<label class="control-label">街道：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span9" type="text" id="input-street" value="'+shopDataArray["STREET"]+'">';
	htmlStr += '</div>     ';
	htmlStr += '</div>';
	htmlStr += '<div class="control-group" id="control-group-address">';
	htmlStr += '<label class="control-label">地址：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span9" type="text" id="input-address" value="'+shopDataArray["ADDRESS"]+'">    ';
	htmlStr += '</div>              ';
	htmlStr += '</div>';
	htmlStr += '<div class="control-group" id="control-group-contact">';
	htmlStr += '<label class="control-label">联系 人：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span9" type="text" id="input-contact" value="'+shopDataArray["CONTACT"]+'">';
	htmlStr += '</div>            ';
	htmlStr += '</div>';
	htmlStr += '<div class="control-group" id="control-group-businessHours">';
	htmlStr += '<label class="control-label">营业时间：</label>';
	htmlStr += '<div class="controls" id="addTime">';
	var hour1="";
	var hour2="";
	var hour3="";
	var temp ;
	var temp1="";
	var temp2="";
	var temp3="";
	var temp4="";
	var temp5="";
	var temp6="";
	var hours= shopDataArray["BUSINESS_HOURS"].split(",");
	if(hours != "" && 0<hours.length && hours.length<=1){
		hour1=hours[0];
		temp = hour1.split("-");
		temp1=temp[0];
		if(temp.length>1){
			temp2=temp[1];
				}
	}else if(hours != "" && 0<hours.length && hours.length<=2){
		hour1=hours[0];
		temp = hour1.split("-");
		temp1=temp[0];
		if(temp.length>1){
			temp2=temp[1];
				}
		hour2=hours[1];
		temp = hour2.split("-");
		temp3=temp[0];
		if(temp.length>1){
			temp4=temp[1];
		}
	}else if(hours != "" && 0<hours.length && hours.length<=3){
		hour1=hours[0];
		temp = hour1.split("-");
		temp1=temp[0];
		if(temp.length>1){
			temp2=temp[1];
				}
		hour2=hours[1];
		temp = hour2.split("-");
		temp3=temp[0];
		if(temp.length>1){
			temp4=temp[1];
		}
		hour3=hours[2];
		temp = hour3.split("-");
		temp5=temp[0];
		if(temp.length>1){
			temp6=temp[1];
		}
	}
	htmlStr += '<label id="hour1">&nbsp;&nbsp;时段1&nbsp;&nbsp;<input type="hidden" id="input-businessHours" value="'+shopDataArray["BUSINESS_HOURS"]+'"><input  type="text" readonly="readonly" class="span2" id="input-businessHours1" value="'+hour1+'" />&nbsp;&nbsp;<input class="Wdate" style="border-color:#ccc; padding:4px 0" id="begin1" onFocus=WdatePicker({Hchanged:$ddf_shop.cHFunc(),mchanged:$ddf_shop.cMFunc(),schanged:$ddf_shop.cSFunc(),dateFmt:"HH:mm",readOnly:false,maxDate:"#F{$dp.$D(\'end1\')}"}) value="'+temp1+'" />&nbsp;&nbsp;-&nbsp;&nbsp;<input class="Wdate" style="border-color:#ccc;padding:4px 0" id="end1" onFocus=WdatePicker({Hchanged:$ddf_shop.cHFunc(),mchanged:$ddf_shop.cMFunc(),schanged:$ddf_shop.cSFunc(),dateFmt:"HH:mm",readOnly:false,minDate:"#F{$dp.$D(\'begin1\')}"}) value="'+temp2+'" /></label>';
	htmlStr += '<label id="hour2">&nbsp;&nbsp;时段2&nbsp;&nbsp;<input type="text" class="span2" readonly="readonly" id="input-businessHours2" value="'+hour2+'" />&nbsp;&nbsp;<input class="Wdate" style="border-color:#ccc;padding:4px 0" id="begin2" onFocus=WdatePicker({Hchanged:$ddf_shop.cHFunc(),mchanged:$ddf_shop.cMFunc(),schanged:$ddf_shop.cSFunc(),dateFmt:"HH:mm",readOnly:false,maxDate:"#F{$dp.$D(\'end2\')}"}) value="'+temp3+'"/>&nbsp;&nbsp;-&nbsp;&nbsp;<input class="Wdate" style="border-color:#ccc;padding:4px 0" id="end2" onFocus=WdatePicker({Hchanged:$ddf_shop.cHFunc(),mchanged:$ddf_shop.cMFunc(),schanged:$ddf_shop.cSFunc(),dateFmt:"HH:mm",readOnly:false,minDate:"#F{$dp.$D(\'begin2\')}"}) value="'+temp4+'"/></label>';
	htmlStr += '<label id="hour3">&nbsp;&nbsp;时段3&nbsp;&nbsp;<input type="text" class="span2" readonly="readonly" id="input-businessHours3" value="'+hour3+'" />&nbsp;&nbsp;<input class="Wdate" style="border-color:#ccc;padding:4px 0" id="begin3" onFocus=WdatePicker({Hchanged:$ddf_shop.cHFunc(),mchanged:$ddf_shop.cMFunc(),schanged:$ddf_shop.cSFunc(),dateFmt:"HH:mm",readOnly:false,maxDate:"#F{$dp.$D(\'end3\')}"}) value="'+temp5+'"/>&nbsp;&nbsp;-&nbsp;&nbsp;<input class="Wdate" style="border-color:#ccc;padding:4px 0" id="end3" onFocus=WdatePicker({Hchanged:$ddf_shop.cHFunc(),mchanged:$ddf_shop.cMFunc(),schanged:$ddf_shop.cSFunc(),dateFmt:"HH:mm",readOnly:false,minDate:"#F{$dp.$D(\'begin3\')}"}) value="'+temp6+'"/></label>';
	//	htmlStr += '<label><input class="Wdate" style="border-color:#ccc;" id="begin" onFocus=WdatePicker({dateFmt:"HH:mm",minDate:"00:00",maxDate:"#F{$dp.$D(\'end\')}"}) />';
//	htmlStr += '&nbsp;&nbsp;-&nbsp;&nbsp;<input class="Wdate" style="border-color:#ccc;" id="end" onFocus=WdatePicker({dateFmt:"HH:mm",minDate:"#F{$dp.$D(\'begin\')}",maxDate:"23:59"}) /></label>';
//	htmlStr += '<label><input class="Wdate" style="border-color:#ccc;" id="begin1" onFocus=WdatePicker({dateFmt:"HH:mm",minDate:"00:00",maxDate:"#F{$dp.$D(\'end1\')}"}) />';
//	htmlStr += '&nbsp;&nbsp;-&nbsp;&nbsp;<input class="Wdate" style="border-color:#ccc;" id="end1" onFocus=WdatePicker({dateFmt:"HH:mm",minDate:"#F{$dp.$D(\'begin1\')}",maxDate:"23:59"}) /></label>';
	htmlStr += '</div>         ';
	htmlStr += '</div>';
	
	htmlStr += '<div class="control-group" id="control-group-businessStatusType">';
	htmlStr += '<label class="control-label">营业状态模式：</label>';
	htmlStr += '<div class="controls">';
	
	
	if(shopDataArray["BUSINESS_STATUS_TYPE"]=="1"){
		
		htmlStr += '<label><input type="radio" name="businessStatusType" value="1" checked="checked" />手动</label><label><input type="radio" name="businessStatusType" value="2"/>自动</label>   ';

	}else{
		
		htmlStr += '<label><input type="radio" name="businessStatusType" value="1" />手动</label><label><input type="radio" name="businessStatusType" value="2" checked="checked" />自动</label>   ';

	}
	
	htmlStr += '</div>         ';
	htmlStr += '</div>';
	
	htmlStr += '<div class="control-group" id="control-group-businessStatus">';
	htmlStr += '<label class="control-label">营业状态：</label>';
	htmlStr += '<div class="controls">';
	
	if(shopDataArray["BUSINESS_STATUS"]=="1"){
		
		htmlStr += '<label><input type="radio" name="businessStatus" value="1" checked="checked" />营业中</label><label><input type="radio" name="businessStatus" value="2"/>休息中</label>   ';

	}else{
		
		htmlStr += '<label><input type="radio" name="businessStatus" value="1" />营业中</label><label><input type="radio" name="businessStatus" value="2" checked="checked" />休息中</label>   ';

	}
	//htmlStr += '<label><input type="radio" name="businessStatus" value="1" checked="checked" />营业中</label>';

	htmlStr += '</div>         ';
	htmlStr += '</div>';
	
	
	htmlStr += ' <div class="control-group" id="control-group-minAmount">';
	htmlStr += '<label class="control-label">起送金额：</label>';
	htmlStr += '<div class="controls" id="control-minAmount">';
	htmlStr += '<input class="span9" type="text" id="input-minAmount"  value="'+shopDataArray["MIN_AMOUNT"]+'">';
	htmlStr += '<span  id="minAmount">(元)</span>';
	htmlStr += '</div>     ';
	htmlStr += '</div>       ';
	
	htmlStr += '<div class="control-group" id="control-group-shopDelivery"><label class="control-label">配送方式：</label><div class="controls" id="radio-shop_delivery"></div></div>';
	
	htmlStr += '<div class="control-group" id="control-group-range">';
	htmlStr += '<label class="control-label">配送范围：</label>';
	htmlStr += '<div class="controls">';
	//htmlStr += '<input class="span9" type="text" id="input-range" value="'+shopDataArray["RANGE"]+'">';
	htmlStr += '<select class="span9" id="input-range">'
		+'<option value="500" '+(shopDataArray["RANGE"]=="500"?'selected="selected"':'')+'>500米</option>'
		+'<option value="1000" '+(shopDataArray["RANGE"]=="1000"?'selected="selected"':'')+'>1000米</option>'
		+'<option value="1500" '+(shopDataArray["RANGE"]=="1500"?'selected="selected"':'')+'>1500米</option>'
		+'<option value="2000" '+(shopDataArray["RANGE"]=="2000"?'selected="selected"':'')+'>2000米</option>'
		+'<option value="2500" '+(shopDataArray["RANGE"]=="2500"?'selected="selected"':'')+'>2500米</option>'
		+'<option value="3000" '+(shopDataArray["RANGE"]=="3000"?'selected="selected"':'')+'>3000米</option>'
		//+'<option value="3500" '+(shopDataArray["RANGE"]=="3500"?'selected="selected"':'')+'>3500米</option>'
		//+'<option value="4000" '+(shopDataArray["RANGE"]=="4000"?'selected="selected"':'')+'>4000米</option>'
		//+'<option value="4500" '+(shopDataArray["RANGE"]=="4500"?'selected="selected"':'')+'>4500米</option>'
		//+'<option value="5000" '+(shopDataArray["RANGE"]=="5000"?'selected="selected"':'')+'>5000米</option>'
		+'</select>';
	htmlStr += '<span id="range">(米)</span>';
	htmlStr += '</div>          ';
	htmlStr += '</div>';
	
	htmlStr += ' <div class="control-group" id="control-group-deliveryAmount">';
	htmlStr += '<label class="control-label">配送费：</label>';
	htmlStr += '<div class="controls" id="control-deliveryAmount">';
	htmlStr += '<input class="span9" type="text" id="input-deliveryAmount"  value="'+shopDataArray["DELIVERY_AMOUNT"]+'">';
	htmlStr += '<span  id="deliveryAmount">(元)</span>';
	htmlStr += '</div>     ';
	htmlStr += '</div>       ';
	
	htmlStr += '<div class="control-group" id="control-group-shipTime">';
	htmlStr += '<label class="control-label">送达时间：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span9" type="text" id="input-shipTime" value="'+shopDataArray["SHIP_TIME"]+'">';
	htmlStr += '<span id="shipTime" >(分钟)</span>';
	htmlStr += '</div>          ';
	htmlStr += '</div>';
	htmlStr += '<div class="control-group" id="control-group-phone">';
	htmlStr += '<label class="control-label">联系电话：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span9" type="text" id="input-phone" value="'+shopDataArray["PHONE"]+'">';
	htmlStr += '</div>          ';
	htmlStr += '</div>';
	htmlStr += '<div class="control-group" id="control-group-mobile">';
	htmlStr += '<label class="control-label">手机号码：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span9" type="text" id="input-mobile" value="'+shopDataArray["MOBILE"]+'">';
	htmlStr += '</div>          ';
	htmlStr += '</div>';
	htmlStr += '<div class="control-group" id="control-group-msgMobile">';
	htmlStr += '<label class="control-label">接收消息手机号码：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span9" type="text" id="input-msgMobile" value="'+shopDataArray["MSG_MOBILE"]+'">';
	htmlStr += '</div>          ';
	htmlStr += '</div>';
	
	
	
	htmlStr += '<div class="control-group" id="control-group-map">';
	htmlStr += '<label class="control-label">地图：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<div style="width: 520px; height: 340px; border: 1px solid gray" id="allmap-edit"></div>';
	htmlStr += '</div>          ';
	htmlStr += '</div>';
	
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">经度：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span9" type="text" id="input-longitude" value="'+shopDataArray["LONGITUDE"]+'" disabled/>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">纬度：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span9" type="text" id="input-latitude" value="'+shopDataArray["LATITUDE"]+'" disabled />';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
/*	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">刷卡费率：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<span class="inp_span" id="input-mcc">'+shopDataArray["MCC"]+'</span>';
	htmlStr += '</div>';
	htmlStr += '</div>';*/
	
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">备注：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span9" type="text" id="input-memo" value="'+shopDataArray["MEMO"]+'">';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
		
	htmlStr += '<div class="form-actions">';
	htmlStr += '<button class="btn btn-primary" type="button" onclick=$ddf_shop.updateShop("'+shopDataArray["SHOP_ID"]+'")>保存</button>';
	htmlStr += ' <button class="btn btn-info" type="button" onclick=$ddf_shop.showDiv("content0")>返回</button>  ';
	htmlStr += '</div>  ';
	htmlStr += '</div>';
	htmlStr += '</div> ';
	htmlStr += '</div>  ';
	htmlStr += '</div>';
	htmlStr += '</div> ';
	htmlStr += '</div>  ';
	
	//$("#content0").html("");//清楚增加用户的DIV，是为了防止input的ID重复
	
//	$("#content0").css("display","none");
//	
//	$("#content1").css("display","block");
	
	showDiv("content1");
	$("#content1").html(htmlStr);
	
//	uploadShopLogoInit();
	
	//上传图片
	upload.ddf_upload("add_shop_logo_button","/Shop/LOGO","$ddf_shop.uploadShopLogoCallBack");
	
	
	$("#locationShowDiv").ddf_location(provinceId,cityId,regionId,{  
		 
    	setLocation:function(_provinceId,_cityId,_regionId){  
    		provinceId=_provinceId;
    		cityId=_cityId;
    		regionId=_regionId;
    		map.allmap("allmap-edit","","",$("#province-name").html()+$("#city-name").html()+$("#region-name").html());
    	}
	 });
//	picRoll();
	
//	findAllProvince();
	
//	findCityByProvince(provinceId);
	
//	findRegionByCity(cityId);
	
	getErpDelivery();//配送方式
	
	map.allmap("allmap-edit",shopDataArray["LATITUDE"],shopDataArray["LONGITUDE"]);
	
	
	
	$("#input-shopName").change(function() {
		
		var shopName=$("#input-shopName").val();
		
		if(isNull(shopName)){
			addErrorMessage("control-group-shopName","input-shopName","商家名称非法");
		}else{
			clearErrorMessage("control-group-shopName");
		}
		
	});
	
	$("#input-introduce").change(function() {
		var introduce=$("#input-introduce").val();
		if(isLength(introduce,800)){
			addErrorMessage("control-group-introduce","input-introduce","商家简介只可包含800个汉字");
		}else{
			clearErrorMessage("control-group-introduce");
		}
	});

	$("#input-comName").change(function() {
		
		var comName=$("#input-comName").val();
		
		if(isNull(comName)){
			addErrorMessage("control-group-comName","input-comName","公司名称非法");
		}else{
			clearErrorMessage("control-group-comName");
		}
		
	});
	
	$("#input-phone").change(function() {
		
		var phone=$("#input-phone").val();
		
		if(!isPhone(phone)){
			addErrorMessage("control-group-phone","input-phone","联系电话非法");
		}else{
			clearErrorMessage("control-group-phone");
		}
		
	});
	$("#input-mobile").change(function() {
		
		var mobile=$("#input-mobile").val();
		
		if(!isMobile(mobile)){
			addErrorMessage("control-group-mobile","input-mobile","手机号码非法");
		}else{
			clearErrorMessage("control-group-mobile");
		}
		
	});
	$("#input-msgMobile").change(function() {
			
			var msgMobile=$("#input-msgMobile").val();
			
			if(!isMobile(msgMobile)){
				addErrorMessage("control-group-msgMobile","input-msgMobile","手机号码非法");
			}else{
				clearErrorMessage("control-group-msgMobile");
			}
			
		});
	
    $("#input-minAmount").change(function() {
		var minAmount=$("#input-minAmount").val();
		if(!isNull(minAmount) && !isNumber2Decimal(minAmount)){
			addErrorMessage("control-group-minAmount","input-minAmount","起送金额格式不正确");
		}else{
			clearErrorMessage("control-group-minAmount");
		}
	});
    
    $("#input-range").change(function() {
		var minAmount=$("#input-range").val();
		if(isNull(minAmount)){
			addErrorMessage("control-group-range","input-range","配送范围非法");
		}else if(!isNumber(minAmount)){
			addErrorMessage("control-group-range","input-range","配送范围格式不正确");
		}else{
			clearErrorMessage("control-group-range");
		}
	});
    
    $("#input-deliveryAmount").change(function() {
		var deliveryAmount=$("#input-deliveryAmount").val();
		if(isNull(deliveryAmount)){
			addErrorMessage("control-group-deliveryAmount","input-deliveryAmount","配送费非法");
		}else if(!isNull(deliveryAmount) && !isNumber2Decimal(deliveryAmount)){
			addErrorMessage("control-group-deliveryAmount","input-deliveryAmount","配送费格式不正确");
		}else{
			clearErrorMessage("control-group-deliveryAmount");
		}
	});
    
    $("#input-shipTime").change(function() {
		var minAmount=$("#input-shipTime").val();
		if(!isNull(minAmount) && !isNumber(minAmount)){
			addErrorMessage("control-group-shipTime","input-shipTime","送达时间格式不正确");
		}else{
			clearErrorMessage("control-group-shipTime");
		}
	});
    
    
}

	function cHFunc(){
		cFunc('h');
		}
	function cMFunc(){
		cFunc('m');
		}
	function cSFunc(){
		cFunc('s');
		}
	function cFunc(who){
		if(who=='h'){
		str='时';
		p='h';
		}
		else if(who=='m'){
		str='分';
		p='m';
		}
		else if(who=='s'){
		str='秒';
		p='d';
		}
		var businessHours1="";
		var businessHours2="";
		var businessHours3="";
		if($("#begin1").val() != undefined && $("#end1").val() != undefined){
			businessHours1=($("#begin1").val()==null || $("#begin1").val()=="")?"":($("#begin1").val()+"-"+$("#end1").val());
			
		}
		if($("#begin2").val() != undefined && $("#end2").val() != undefined){
			
			businessHours2=($("#begin2").val()==null || $("#begin2").val()=="")?"":($("#begin2").val()+"-"+$("#end2").val());
		}
		if($("#begin3").val() != undefined && $("#end3").val() != undefined){
			businessHours3=($("#begin3").val()==null || $("#begin3").val()=="")?"":($("#begin3").val()+"-"+$("#end3").val());
			
		}
		$("#input-businessHours1").val(businessHours1);
		$("#input-businessHours2").val(businessHours2);
		$("#input-businessHours3").val(businessHours3);
	}


function checkTime(){
	var temp1="";
	var temp2="";
	var temp3="";
	var temp4="";
	var temp5="";
	var temp6="";
	temp1=$("#begin1").val();
	temp2=$("#end1").val();
	temp3=$("#begin2").val();
	temp4=$("#end2").val();
	temp5=$("#begin3").val();
	temp6=$("#end3").val();
	var businessHours1="";
	var businessHours2="";
	var businessHours3="";
	var busHours="";
	if((temp1 =="" && temp2 !="") || (temp1 !="" && temp2 =="")){
		return false;
	}else if((temp3 =="" && temp4 !="") || (temp3 !="" && temp4 =="")){
		return false;
	}else if((temp5 =="" && temp6 !="") || (temp5 !="" && temp6 =="")){
		return false;
	}else{
		businessHours1+=(($("#input-businessHours1").val()==null || $("#input-businessHours1").val()=="" || $("#input-businessHours1").val()=="-")?"":($("#input-businessHours1").val()));
		businessHours2+=(($("#input-businessHours2").val()==null || $("#input-businessHours2").val()=="" || $("#input-businessHours2").val()=="-")?"":(","+$("#input-businessHours2").val()));
		businessHours3+=(($("#input-businessHours3").val()==null || $("#input-businessHours3").val()=="" || $("#input-businessHours3").val()=="-")?"":(","+$("#input-businessHours3").val()));
		busHours=businessHours1+businessHours2+businessHours3;
		$("#input-businessHours").val(busHours);
		return true;
	}
}
/**
 * 上传商家LOGO
 */
exports.uploadShopLogoCallBack=function(dataObj){
	var dataPath = "";
	if(dataObj.code == "1"){
		for(var i=0;i<dataObj.files.length;i++){
			if(dataObj.files[i].repCode=="1"){
				dataPath = dataObj.files[i].path;
				$("#shopLogoUrl").attr("src", fileOpenUrl + dataPath);
				$("#shopLogoUrlInput").val(dataPath);
			}else{
				base.tips_error("上传失败!");
			}
		}
	}
	
	base.cancelLoading();
}





var updateShopFlag=false;

/**
 * 修改商家
 * @param shopId
 */
function updateShop(){
	if(!checkTime()){
		addErrorMessage("control-group-businessHours","end1","时间段须成对");
		return;
	}else{
		clearErrorMessage("control-group-businessHours");
		var shopName=$("#input-shopName").val();
		var introduce=$("#input-introduce").val();
		var comName=$("#input-comName").val();
		var street=$("#input-street").val();
		var address=$("#input-address").val();
		var contact=$("#input-contact").val();
		var businessHours=$("#input-businessHours").val();
		var minAmount=$("#input-minAmount").val();
		var deliveryAmount=$("#input-deliveryAmount").val();
		var range=$("#input-range").val();
		var shipTime=$("#input-shipTime").val();
		var phone=$("#input-phone").val();
		var mobile=$("#input-mobile").val();
		//var logoUrl=$("#input-logoUrl").val();
		var longitude=$("#input-longitude").val();
		var latitude=$("#input-latitude").val();
		var shopLogoUrlInput=$("#shopLogoUrlInput").val();
		//var mcc=$("#input-mcc").val();
		var mcc="";
		var memo=$("#input-memo").val();
		var msgMobile = $("#input-msgMobile").val();
		var businessStatusType=$('input[name="businessStatusType"]:checked').val();
		var businessStatus=$('input[name="businessStatus"]:checked').val();
		
		var deliveryTypechk = document.getElementsByName("deliveryType");
		var shopDeliveryId="";
		for (var i = 0; i < deliveryTypechk.length; i++) {
			if (deliveryTypechk[i].checked) {
				if(i!=0){
					shopDeliveryId+=",";
				}
				shopDeliveryId += deliveryTypechk[i].value;
			}
		}
		
		
		if(isNull(shopName)){
			addErrorMessage("control-group-shopName","input-shopName","商家名称非法");
			return;
		}
		
		if(isLength(introduce,800)){
			addErrorMessage("control-group-introduce","input-introduce","商家简介只可包含800个汉字");
			return;
		}
		
		if(isNull(comName)){
			addErrorMessage("control-group-comName","input-comName","公司名称非法");
			return;
		}
		
		if(provinceId==""||cityId==""||regionId==""){
			addErrorMessage("control-group-area","","请选择省市区");
			return;
		}
		if(isNull(range)){
			addErrorMessage("control-group-range","input-range","配送范围非法");
			return;
		}
		if(isNull(deliveryAmount)){
			addErrorMessage("control-group-deliveryAmount","input-deliveryAmount","配送费非法");
			return;
		}else if(!isNull(deliveryAmount) && !isNumber2Decimal(deliveryAmount)){
			addErrorMessage("control-group-deliveryAmount","input-deliveryAmount","配送费格式不正确");
			return;
		}
		if(!isPhone(phone)){
			addErrorMessage("control-group-phone","input-phone","联系电话非法");
			return;
		}
		if(!isMobile(mobile)){
			addErrorMessage("control-group-mobile","input-mobile","手机号码非法");
			return;
		}
		if(!isMobile(msgMobile)){
			addErrorMessage("control-group-msgMobile","input-msgMobile","手机号码非法");
			return;
		}
		
		var params={
				"shopName":shopName,
				"introduce":introduce,
				"comName":comName,
				"shopTypeId":shopTypeId,
				"agentId":agentId,
				"provinceId":provinceId,
				"cityId":cityId,
				"regionId":regionId,
				"street":street,
				"address":address,
				"contact":contact,
				"businessHours":businessHours,
				"minAmount":minAmount,
				"range":range,
				"shipTime":shipTime,
				"phone":phone,
				"mobile":mobile,
				"logoUrl":shopLogoUrlInput,
				"longitude":longitude,
				"latitude":latitude,
				"mcc":mcc,
				"memo":memo,
				"businessStatusType":businessStatusType,
				"businessStatus":businessStatus,
				"msgMobile":msgMobile,
				"deliveryAmount":deliveryAmount,
				"shopDeliveryId":shopDeliveryId
		};
		
		tips_index=1;
		
		base.showLoading();
		
		eval(Wind.compile("async",function(){
			
			var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.shop.editShop,params));
			
			updateShopCallBack(data);
			
		}))().start();
		
	}
	
}

/**
 * 修改商家_回调函数
 */
function updateShopCallBack(data){

	if(data["code"]==1){
		
//		back("content1","content0");
		showDiv("content0");
		
		updateShopFlag=true;
		
//		loadShopDetail($("#edit_shopId").html());
//		init();
		loadShopMessage();
		

	}else{
		
		updateShopFlag=false;
		
		base.tips_error(data["message"]);
		
    }

	base.cancelLoading();
}







/**
 * 选择商家类型
 */

var shopTypeId="";

function setShopType(_shopTypeId){
	
	shopTypeId=_shopTypeId;
}





/**
 * 打开商家类型列表
 */
exports.openShopTypeDialog=function(){
	dialog.ddf_dialog_shop_type($("#input-shopType"),function(id,name){  
		
		$("#input-shopType").val(name);
		
		setShopType(id);
		
    });
	
};


/**
 * 配送方式列表
 */
function getErpDelivery(){
	eval(Wind.compile("async",function(){
		
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.shop.getErpDeliveryList,""));
		
		getErpDeliveryCallBack(data);
		
	}))().start();
}

function getErpDeliveryCallBack(data){
	
	var htmlStr="";
	
	for(var i=0;i<data["erpDeliveryListData"].length;i++){
		
		if(isExitsDelivery(data["erpDeliveryListData"][i]["DELIVERY_ID"])){
			
			htmlStr+='<label><input type="checkbox" name="deliveryType" value="'+data["erpDeliveryListData"][i]["DELIVERY_ID"]+'" checked/>'+data["erpDeliveryListData"][i]["DELIVERY_NAME"]+'</label>';

		}else{
		
			htmlStr+='<label><input type="checkbox" name="deliveryType" value="'+data["erpDeliveryListData"][i]["DELIVERY_ID"]+'"/>'+data["erpDeliveryListData"][i]["DELIVERY_NAME"]+'</label>';

		}
		
	}
		
	$("#radio-shop_delivery").html(htmlStr);
	
	$("input[name='deliveryType'][value='1']").attr("checked",true);
	$("input[name='deliveryType'][value='1']").attr("disabled",true);
	
	base.setRadioStyle();
}

/**
 * 判断商家是否存在该配送方式
 * @param id
 * @returns 
 */
function isExitsDelivery(id){
	
	if(deliveryIdHtml!=""){
		
		var deliveryIdArray=deliveryIdHtml.split(",")
		
		for(var i=0;i<deliveryIdArray.length;i++){
			
			if(id==deliveryIdArray[i])
				return true;
			
		}
		
	}
	
	return false;
}

/**
 * 设置营业状态
 * @param status
 */
exports.setBusinessStatus=function(status,name){
	
	$("#show_shopStatusName").html(name);
	
	//当用户选择的是原来的状态，则不执行修改操作
	if(shopDataArray["BUSINESS_STATUS"]==status){
		return;
	}
	var params={
			"businessStatus":status
	};
	
	base.showLoading();
	
	eval(Wind.compile("async",function(){
		
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.shop.updateBusinessStatus,params));
		
		updateShopCallBack(data);
		
	}))().start();
};


/**
 * 商家相册管理
 */
exports.openShopPhotos=function(){
	history.addHis(this,arguments);//增加历史
	var htmlStr ="";
	htmlStr += '<div id="content-header">';
	htmlStr += '<div id="breadcrumb"> <a href=javascript:load("'+ddf.index.index_js+'") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href=javascript:$ddf_shop.showDiv("content0")>商家管理</a><a href="javascript:void(0)" class="current">商家相册管理</a></div>';
	htmlStr += '</div>';

	htmlStr += '<div class="container-fluid">';
	htmlStr += '<div class="row-fluid">';
	htmlStr += '<div class="span12">';
	
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title"><span class="icon"><i class="icon-pencil"></i></span><h5>操作</h5></div>    ';
	htmlStr += '<div class="widget-content"><div class="div-btn">';
	htmlStr += '<button class="btn btn-success" type="button" onClick=$ddf_shop.showDiv("content0")>返回</button>';
	htmlStr += '</div></div>';
	htmlStr += '</div>  ';
	
	htmlStr += '<div class="widget-box"><div class="widget-title"> <span class="icon"><i class="icon-picture"></i></span>';
	htmlStr += '<h5>商家相册</h5>';
	htmlStr += '</div>';
	
	htmlStr += '<div class="widget-content">';
	htmlStr += '<div class="form-horizontal">';
	htmlStr += '<ul class="thumbnails" id="shopsPhotos_ul">';
	
	htmlStr += '</ul>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
	
	showDiv("content2");
	$("#content2").html(htmlStr);
    
	getShopPhoto();
	
};


/**
 * 加载相册相片
 */
function getShopPhoto(){

	base.showLoading();
	eval(Wind.compile("async",function(){
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.shop.queryShopPhoto,""));
		
		getShopPhotoCallBack(data);
		
	}))().start();
	
	
}

function getShopPhotoCallBack(data){
	if(data["code"]==1){
		var htmlStr="";
		for(var i=0;i<10;i++){
			htmlStr += '<li class="span2 shopsPhotos"> <a id="aLink'+i+'" class="lightbox_trigger" href="../img/photos.png"><img id="imgLink'+i+'" src="../admin/img/photos.png" alt="" > </a>';
			htmlStr += '<div class="actions"> ';
			htmlStr += '<a id="d'+i+'" title="" class="delete_this" href="#"><i class="icon-trash"></i></a> &nbsp;';
			htmlStr += '<a id="u'+i+'" title="" class="upload_this" href="#"><i class="icon-upload-alt"></i></a> &nbsp;<span id="span'+i+'" style="display:none">0</span>';
			htmlStr += '</div>';
			htmlStr += '<div input id="divLink'+i+'"><div>';
			htmlStr += '</li>';
		}
		
		$("#shopsPhotos_ul").html(htmlStr);
		
		for(var i=0;i<data["erpShopImageList"].length;i++){
			
			var sort=data["erpShopImageList"][i]["SORT"];
			var path=data["erpShopImageList"][i]["IMAGE_URL"];
			var imgId=data["erpShopImageList"][i]["IMAGE_ID"];
			
			$("#aLink"+sort).attr("href",fileOpenUrl+path);
			$("#imgLink"+sort).attr("src",fileOpenUrl+path);
			$("#span"+sort).text(imgId);
			
		}
		
		$(".shopsPhotos .delete_this").on("click",function(){
			var sort = $(this).attr("id");
			var index=sort.substring(1);
			var imgId = $("#span"+index).text();
			if(imgId=="0"){
				base.tips_error("此位置没有照片，无法删除！");
				return;
			}else{
				//设置全局变量
				photoParm["index"]=index;
				photoParm["imgId"]=imgId;
				photoTips("删除");
//				if (confirm("确定要删除第"+(parseInt(index)+1)+"张相片?")) {
//					deleteShopPhoto(index,imgId);
//				}
			}
			
		});
		$(".shopsPhotos .upload_this").on("click",function(){
			//$(this).parents(".shopsPhotos").find("input").click();	
			var sort = $(this).attr("id");
			var index=sort.substring(1);
			clickId=index;//赋值选中的控件ID
			
			if($("#span"+clickId).text()!="0"){
				//弹窗提示
				photoTips("更新");
				photoParm["index"]=index;
				photoParm["path"]="/shop/shop"+shopDataArray["SHOP_ID"]+"/shopPhotos";
				photoParm["callback"]="$ddf_shop.uploadShopPhotosCallBack";
			}else{
				upload.ddf_upload_shopPhots(index,"/shop/shop"+shopDataArray["SHOP_ID"]+"/shopPhotos","$ddf_shop.uploadShopPhotosCallBack");
			}
			
			
		});

		$('.lightbox_trigger').click(function(e) {
			
			e.preventDefault();
			
			var image_href = $(this).attr("href");
			
			if ($('#lightbox').length > 0) {
				
				$('#imgbox').html('<img src="' + image_href + '" /><p><i class="icon-remove icon-white"></i></p>');
			   	
				$('#lightbox').slideDown(500);
			}
			
			else { 
				var lightbox = 
				'<div id="lightbox" style="display:none;">' +
					'<div id="imgbox"><img src="' + image_href +'" />' + 
						'<p><i class="icon-remove icon-white"></i></p>' +
					'</div>' +	
				'</div>';
					
				$('body').append(lightbox);
				$('#lightbox').slideDown(500);
			}
			
		});
		
		$('#lightbox').live('click', function() { 
			$('#lightbox').hide(200);
		});
		
	}else{
		
		 base.tips_error(data["message"]);
	}

	base.cancelLoading();
}



/**
 * 上传商家相册回调函数
 */
var clickId="";
var photoParm={};
exports.uploadShopPhotosCallBack=function(dataObj){
	
	var dataPath = "";
	if(dataObj.code == "1"){
		
		for(var i=0;i<dataObj.files.length;i++){
			if(dataObj.files[i].repCode=="1"){
				dataPath = dataObj.files[i].path;
//				$("#aLink"+clickId).attr("href",fileOpenUrl+dataPath);
//				$("#imgLink"+clickId).attr("src",fileOpenUrl+dataPath);
				if($("#span"+clickId).text()=="0"){
					//当该位置的没有照片时，则添加照片
					addShopPhoto(clickId,dataPath);
				}else{
					//当该位置的存在照片时，则更新照片
					updateShopPhoto($("#span"+clickId).text(),clickId,dataPath);
				}
				
			}else{
				base.tips_error("上传失败!");
			}
		}
	}
	clickId="";
	base.cancelLoading();
};



/**
 * 插入商家相册
 */
function addShopPhoto(_sort,_path){
	
	var params={
			"sort":_sort,
			"imageUrl":_path
			
	};
	
	eval(Wind.compile("async",function(){
		
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.shop.updateShopPhoto,params));
		
		shopPhotoCallBack(data);
		
	}))().start();
};

/**
 * 更新商家相册
 */
function updateShopPhoto(_imageId,_sort,_path){
	
	var params={
			"imageId":_imageId,
			"sort":_sort,
			"imageUrl":_path
			
	};
	
	eval(Wind.compile("async",function(){
		
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.shop.updateShopPhoto,params));
		
		shopPhotoCallBack(data);
		
	}))().start();
	
};

/**
 * 删除相册相片
 */
function deleteShopPhoto(_sort,_imageId){
	var params={
			"sort":_sort,
			"imageId":_imageId
	};
	
	eval(Wind.compile("async",function(){
		
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.shop.deleteShopPhoto,params));
		
		shopPhotoCallBack(data);
		
	}))().start();
}


/**
 * 相册插入、更新、删除的回调函数
 */
function shopPhotoCallBack(data){
	if(data["code"]==1){
		base.tips(data["message"]);
		getShopPhoto();
	}else{
		base.tips_error(data["message"]);
    }
	$("#tip").remove();	
	$("body .modal-backdrop").remove();	
	photoParm={};
};


//弹窗提示
function photoTips(_oper){
	var title=_oper+"提示";
	var info="是否确认"+_oper+"此位置的照片！";
//	var href=_fn;
	var btnleft="确定";
	var btnright="取消";
	var noplayer=
		'<div id="tip" class="modal">' +
			 '<div class="modal-header">' +
				 '<button class="close over" type="button">×</button>' +
				 '<h3>'+title+'</h3>' +
			 '</div>' +
			 '<div class="modal-body">'+
				 '<p>'+info+'</p>'+
			 '</div>'+
//			 '<div class="modal-footer"> <a class="btn btn-primary" onclick="'+href+'">'+btnleft+'</a> <button class="btn over">'+btnright+'</button> </div>'+

			 '<div class="modal-footer"> <button class="btn btn-primary">'+btnleft+'</button> <button class="btn over">'+btnright+'</button> </div>'+
		'</div>';
	$(noplayer).appendTo("body");
	$("<div class='modal-backdrop in'></div>").appendTo("body");
	$("#tip").find(".btn-primary").click(function(){
		if(_oper=="删除"){
			deleteShopPhoto(photoParm["index"],photoParm["imgId"]);
		}else if(_oper=="更新"){
			upload.ddf_upload_shopPhots(photoParm["index"],photoParm["path"],photoParm["callback"]);
		}
		
	});
	$("#tip").find(".over").click(function(){
		$("#tip").remove();	
		$("body .modal-backdrop").remove();	
	});
}

//下载二维码页面
exports.showDownMerCode  = function() {

	var divcont = '<div class="big_modal" id="showDownId" style="margin-top:'+myScrollTop+'px">'
			+ '<div class="modal-header">'
			+ '<button class="close over" type="button">×</button>'
			+ '<h3>二维码尺寸</h3>'
			+ '</div>'
			+ '<div>'
			+ '<div class="widget-content nopadding dataTables_wrapper">'
			+ '<table class="table table-bordered data-table">'
			 + '<thead>' + '<tr>'
			+ '<th>二维码边长(cm)</th>' + '<th>建议扫描距离(米)</th>' + '<th>下载链接</th>'  + '</tr>'
			+ '</thead>' + '<tbody id="">' 
			+ '<tr><td class="center">8cm</td><td class="center">0.5m</td><td class="center"><a href="javascript:$ddf_shop.downCode(1);">下载</a></td></tr>'
			+ '<tr><td class="center">12cm</td><td class="center">0.8m</td><td class="center"><a href="javascript:$ddf_shop.downCode(2);">下载</a></td></tr>'
			+ '<tr><td class="center">15cm</td><td class="center">1m</td><td class="center"><a href="javascript:$ddf_shop.downCode(3);">下载</a></td></tr>'
//			+ '<tr><td class="center">30cm</td><td class="center">1.5m</td><td class="center"><a href="javascript:$$ddf_shop.downCode(4);">下载</a></td></tr>'
//			+ '<tr><td class="center">50cm</td><td class="center">2.5m</td><td class="center"><a href="javascript:$$ddf_shop.downCode(5);">下载</a></td></tr>'
			+ '</tbody>'
			+ '</table>'  + '</div>'
			+ '</div>' + '</div>'
			+ '<div class="big_modal-backdrop in"></div>';

	$(divcont).appendTo("body");

	$("#showDownId").find(".over").click(
		function() {$("#showDownId").remove();
			$("body .big_modal-backdrop").remove();
		});
}

/**
 * 下载二维码
 */
exports.downCode=function(_size){
	$("#showDownId").remove();
	$("body .big_modal-backdrop").remove();
	
	var size = "";
	if(_size == 1){
		size = "&w=945&h=945";
	}else if(_size == 2){
		size = "&w=1417&h=1417";
	}else if(_size == 3){
		size = "&w=1772&h=1772";
	}else if(_size == 4){
		size = "&w=3543&h=3543";
	}else if(_size == 5){
		size = "&w=5906&h=5906";
	}else{
		size = "&w=945&h=945";
	}
	
    var image = CTX+"/QrCodeServlet?m=" + content+size;   
    
    var filename = '云便利商店_' + $("#show_shopName").html() + '.png'  ;
    
    if(document.all) {//IE用
        window.frames["hrong"].location.href   =   image;     
        $ddf_shop.sa();   
    }else if (document.createEvent) {
    	var save_link = document.createElement("a");
        save_link.href = image;
        save_link.download = filename;

        var event = document.createEvent('MouseEvents');
        event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
        save_link.dispatchEvent(event);
    }
};

//页面滚动
var myScrollTop=0;
window.onscroll=function(){	
	function get_scrollTop_of_body(){ //scrollTop能力检测函数
				var scrollTop; 
				if(typeof window.pageYOffset != 'undefined'){ 
				scrollTop = window.pageYOffset; 
				} 
				else 
				if(typeof document.compatMode != 'undefined' && 
				document.compatMode != 'BackCompat'){ 
				scrollTop = document.documentElement.scrollTop; 
				} 
				else 
				if(typeof document.body != 'undefined'){ 
				scrollTop = document.body.scrollTop; 
				} 
				return scrollTop; 
	}
	 myScrollTop = parseInt(get_scrollTop_of_body());//获取ScrollTop的值
}


function showDiv(block){
	
	$("#content > div").hide();
	
	if($("#"+block).length<=0){
		
		$("#content").append('<div id="'+block+'"></div>'); 
		
	}else{
		
		$("#"+block).show();
	}
}

//暴露方法
//exports={};
exports.loadShopDetailCallBack=loadShopDetailCallBack;
exports.editShop=editShop;
exports.updateShop=updateShop;
exports.updateShopCallBack=updateShopCallBack;
exports.setShopType=setShopType;
exports.showDiv = showDiv;
exports.checkTime = checkTime;
exports.cHFunc = cHFunc;
exports.cMFunc = cMFunc;
exports.cSFunc = cSFunc;
});
//})();
